<!--
 * @Author: HC
 * @Date: 2022-04-22 14:42:31
 * @LastEditTime: 2022-04-22 17:01:19
 * @Description:
-->
<template>
  <div class="comparison">
    <div class="table">
      <el-table
        :data="tableData"
        border
        :header-cell-style="headerClass"
        v-loading="tableLoading"
      >
        <el-table-column
          v-for="(item, index) in headerData"
          :key="index"
          :label="item"
          :prop="item"
          align="center"
        ></el-table-column>
      </el-table>
      <div style="width: 100%; height: 300px;padding:20px 0" id="zyCharts"></div>
      <el-table
        :data="tableData1"
        border
        :header-cell-style="headerClass"
        v-loading="tableLoading1"
      >
        <el-table-column
          v-for="(item, index) in headerData1"
          :key="index"
          :label="item"
          :prop="item"
          align="center"
        ></el-table-column>
      </el-table>
      <div style="width: 100%; height: 300px;padding:20px 0" id="mhCharts"></div>
      <el-table
        :data="tableData2"
        border
        :header-cell-style="headerClass"
        v-loading="tableLoading2"
      >
        <el-table-column
          v-for="(item, index) in headerData2"
          :key="index"
          :label="item"
          :prop="item"
          align="center"
        ></el-table-column>
      </el-table>
      <div style="width: 100%; height: 300px;padding:20px 0" id="tjCharts"></div>
      <el-table
        :data="tableData3"
        border
        :header-cell-style="headerClass"
        v-loading="tableLoading3"
      >
        <el-table-column
          v-for="(item, index) in headerData3"
          :key="index"
          :label="item"
          :prop="item"
          align="center"
        ></el-table-column>
      </el-table>
      <div style="width: 100%; height: 300px;padding:20px 0" id="cyCharts"></div>
    </div>
  </div>
</template>

<script>
import $barCodeApi from "@/api/barCode/index";
export default {
  name: "comparison",
  components: {},
  props: {
    form: {
      type: Object,
      default: {},
    },
  },
  data() {
    return {
      tableLoading: false,
      tableData: [],
      headerData: [],
      tableLoading1: false,
      tableData1: [],
      headerData1: [],
      tableLoading2: false,
      tableData2: [],
      headerData2: [],
      tableLoading3: false,
      tableData3: [],
      headerData3: [],
    };
  },
  computed: {},
  created() {},
  mounted() {},
  methods: {
    getList() {
      this.tableLoading = true;
      this.tableLoading1 = true;
      this.tableLoading2 = true;
      this.tableLoading3 = true;
      $barCodeApi.getZyIncome({ ...this.form }, (res) => {
        if (res.code == 0) {
          this.tableLoading = false;
          this.headerData = res.content.month;
          var arr = [];
          var charts = []
          var charts1 = []
          var charts2 = []
          res.content.date.forEach((item,idx) => {
            let obj = {};
            item.forEach((its, index) => {
              if (index > 0 && idx == 0) {
                charts.push(its.thisMonthIncome)
              } else if (index > 0 && idx == 1) {
                charts1.push(its.thisMonthIncome)
              } else if (index > 0 && idx == 2) {
                charts2.push(its.thisMonthIncome)
              }
              if (idx == 2) {
                  obj[res.content.month[index]] = its.thisMonthIncome + '%';
              } else {
                  obj[res.content.month[index]] = its.thisMonthIncome;
              }
            });
            arr.push(obj);
          });
          this.tableData = arr;
          this.showZyCharts(charts,charts1,charts2);
        }
      });
      $barCodeApi.getMhIncome({ ...this.form }, (res) => {
        if (res.code == 0) {
          this.tableLoading1 = false;
          this.headerData1 = res.content.month;
          var mhArr = [];
          var mhCharts = []
          var mhCharts1 = []
          var mhCharts2 = []
          res.content.date.forEach((item,idx) => {
            let obj = {};
            item.forEach((its, index) => {
              if (index > 0 && idx == 0) {
                mhCharts.push(its.thisMonthIncome)
              } else if (index > 0 && idx == 1) {
                mhCharts1.push(its.thisMonthIncome)
              } else if (index > 0 && idx == 2) {
                mhCharts2.push(its.thisMonthIncome)
              }
              obj[res.content.month[index]] = its.thisMonthIncome;
            });
            mhArr.push(obj);
          });
          this.tableData1 = mhArr;
          this.showMhCharts(mhCharts,mhCharts1,mhCharts2);
        }
      });
      $barCodeApi.getTjIncome({ ...this.form }, (res) => {
        if (res.code == 0) {
          this.tableLoading2 = false;
          this.headerData2 = res.content.month;
          var tjArr = [];
          var tjCharts = []
          var tjCharts1 = []
          var tjCharts2 = []
          res.content.date.forEach((item,idx) => {
            let obj = {};
            item.forEach((its, index) => {
              if (index > 0 && idx == 0) {
                tjCharts.push(its.thisMonthIncome)
              } else if (index > 0 && idx == 1) {
                tjCharts1.push(its.thisMonthIncome)
              } else if (index > 0 && idx == 2) {
                tjCharts2.push(its.thisMonthIncome)
              }
              obj[res.content.month[index]] = its.thisMonthIncome;
            });
            tjArr.push(obj);
          });
          this.tableData2 = tjArr;
          this.showTjCharts(tjCharts,tjCharts1,tjCharts2);
        }
      });
      $barCodeApi.getCyIncome({ ...this.form }, (res) => {
        if (res.code == 0) {
          this.tableLoading3 = false;
          this.headerData3 = res.content.month;
          var cyArr = [];
          var cyCharts = []
          var cyCharts1 = []
          var cyCharts2 = []
          res.content.date.forEach((item,idx) => {
            let obj = {};
            item.forEach((its, index) => {
              if (index > 0 && idx == 0) {
                cyCharts.push(its.thisMonthIncome)
              } else if (index > 0 && idx == 1) {
                cyCharts1.push(its.thisMonthIncome)
              } else if (index > 0 && idx == 2) {
                cyCharts2.push(its.thisMonthIncome)
              }
              if (idx == 2) {
                obj[res.content.month[index]] = its.thisMonthIncome + '%';
              } else {
                obj[res.content.month[index]] = its.thisMonthIncome;
              }
            });
            cyArr.push(obj);
          });
          this.tableData3 = cyArr;
          this.showCyCharts(cyCharts,cyCharts1,cyCharts2);
        }
      });
    },
    showZyCharts(charts,charts1,charts2) {
        let max = charts2.reduce((a,b) => {
            return Number(b)>Number(a) ? b:a
        })
      var chartDom = document.getElementById("zyCharts");
      var myChart = this.$echarts.init(chartDom);
      var option;

      option = {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            crossStyle: {
              color: "#999",
            },
          },
        },
        legend: {
          data: ["2022累计同比", "2021年完成(万元)", "2022年完成(万元)"],
        },
        xAxis: [
          {
            type: "category",
            data: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],
            axisPointer: {
              type: "shadow",
            },
          },
        ],
        yAxis: [{
            splitLine: {
                show: false,
            },
            axisLabel: {
                show: false,
            },
            axisTick: {
                show: false,
            },
            axisLine: {
                show: false,
            },
        },
        {
            type: "value",
            max: max*2,
            splitLine: {
                show: false,
            },
            axisLabel: {
                show: false,
            },
            axisTick: {
                //y轴刻度线
                show: false,
            },
            axisLine: {
                //y轴
                show: false,
            },
        }],
        series: [
          {
            name: "2022累计同比",
            type: "bar",
            barWidth: 30,
            yAxisIndex: 1,
            itemStyle: {
                normal: {
                    color: "#B4C7E7",
                    label: {
                        show: true,
                        position: 'top',
                        textStyle: {
                            color: "#0070CB",
                            fontSize: 10
                        },
                        formatter:function(params){ //标签内容
                            return  params.value+'%'
                        },
                    }
                },
            },
            data: charts2
          },
          {
            name: "2021年完成(万元)",
            type: "line",
            itemStyle: {
                normal: {
                    color: "#00B050",
                    label: {
                        show: true,
                        position: 'bottom',
                        textStyle: {
                            color: "#00B050",
                            fontSize: 10
                        },
                    }
                },
            },
            data: charts,
          },
          {
            name: "2022年完成(万元)",
            type: "line",
            itemStyle: {
                normal: {
                    color: "#FF0000",
                    label: {
                        show: true,
                        position: 'top',
                        textStyle: {
                            color: "#FF0000",
                        },
                    }
                },
            },
            data: charts1,
          },
        ],
      };

      option && myChart.setOption(option);
    },
    showMhCharts(mhCharts,mhCharts1,mhCharts2){
        let max = mhCharts2.reduce((a,b) => {
            return Number(b)>Number(a) ? b:a
        })
        var chartDom = document.getElementById("mhCharts");
      var myChart = this.$echarts.init(chartDom);
      var option;

      option = {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            crossStyle: {
              color: "#999",
            },
          },
        },
        legend: {
          data: ["2022年环比增幅(万元)", "2021年完成(万元)", "2022年完成(万元)"],
        },
        xAxis: [
          {
            type: "category",
            data: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],
            axisPointer: {
              type: "shadow",
            },
          },
        ],
        yAxis: [{
            splitLine: {
                show: false,
            },
            axisLabel: {
                show: false,
            },
            axisTick: {
                show: false,
            },
            axisLine: {
                show: false,
            },
        },
        {
            type: "value",
            max: max*2,
            splitLine: {
                show: false,
            },
            axisLabel: {
                show: false,
            },
            axisTick: {
                //y轴刻度线
                show: false,
            },
            axisLine: {
                //y轴
                show: false,
            },
        }],
        series: [
          {
            name: "2022年环比增幅(万元)",
            type: "bar",
            barWidth: 30,
            yAxisIndex: 1,
            itemStyle: {
                normal: {
                    color: "#B4C7E7",
                    label: {
                        show: true,
                        position: 'top',
                        textStyle: {
                            color: "#0070CB",
                            fontSize: 10
                        },
                    }
                },
            },
            data: mhCharts2
          },
          {
            name: "2021年完成(万元)",
            type: "line",
            itemStyle: {
                normal: {
                    color: "#00B050",
                    label: {
                        show: true,
                        position: 'bottom',
                        textStyle: {
                            color: "#00B050",
                            fontSize: 10
                        },
                    }
                },
            },
            data: mhCharts,
          },
          {
            name: "2022年完成(万元)",
            type: "line",
            itemStyle: {
                normal: {
                    color: "#FF0000",
                    label: {
                        show: true,
                        position: 'top',
                        textStyle: {
                            color: "#FF0000",
                        },
                    }
                },
            },
            data: mhCharts1,
          },
        ],
      };

      option && myChart.setOption(option);
    },
    showTjCharts(tjCharts,tjCharts1,tjCharts2){
        let max = tjCharts2.reduce((a,b) => {
            return Number(b)>Number(a) ? b:a
        })
        var chartDom = document.getElementById("tjCharts");
      var myChart = this.$echarts.init(chartDom);
      var option;

      option = {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            crossStyle: {
              color: "#999",
            },
          },
        },
        legend: {
          data: ["2022年环比增幅(万元)", "2021年完成(万元)", "2022年完成(万元)"],
        },
        xAxis: [
          {
            type: "category",
            data: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],
            axisPointer: {
              type: "shadow",
            },
          },
        ],
        yAxis: [{
            splitLine: {
                show: false,
            },
            axisLabel: {
                show: false,
            },
            axisTick: {
                show: false,
            },
            axisLine: {
                show: false,
            },
        },
        {
            type: "value",
            max: max*2,
            splitLine: {
                show: false,
            },
            axisLabel: {
                show: false,
            },
            axisTick: {
                //y轴刻度线
                show: false,
            },
            axisLine: {
                //y轴
                show: false,
            },
        }],
        series: [
          {
            name: "2022年环比增幅(万元)",
            type: "bar",
            barWidth: 30,
            yAxisIndex: 1,
            itemStyle: {
                normal: {
                    color: "#B4C7E7",
                    label: {
                        show: true,
                        position: 'top',
                        textStyle: {
                            color: "#0070CB",
                            fontSize: 10
                        },
                    }
                },
            },
            data: tjCharts2
          },
          {
            name: "2021年完成(万元)",
            type: "line",
            itemStyle: {
                normal: {
                    color: "#00B050",
                    label: {
                        show: true,
                        position: 'bottom',
                        textStyle: {
                            color: "#00B050",
                            fontSize: 10
                        },
                    }
                },
            },
            data: tjCharts,
          },
          {
            name: "2022年完成(万元)",
            type: "line",
            itemStyle: {
                normal: {
                    color: "#FF0000",
                    label: {
                        show: true,
                        position: 'top',
                        textStyle: {
                            color: "#FF0000",
                        },
                    }
                },
            },
            data: tjCharts1,
          },
        ],
      };

      option && myChart.setOption(option);
    },
    showCyCharts(cyCharts,cyCharts1,cyCharts2){
        let max = cyCharts2.reduce((a,b) => {
            return Number(b)>Number(a) ? b:a
        })
        var chartDom = document.getElementById("cyCharts");
      var myChart = this.$echarts.init(chartDom);
      var option;

      option = {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            crossStyle: {
              color: "#999",
            },
          },
        },
        legend: {
          data: ["累计同比增幅", "2021年完成(万元)", "2022年完成(万元)"],
        },
        xAxis: [
          {
            type: "category",
            data: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],
            axisPointer: {
              type: "shadow",
            },
          },
        ],
        yAxis: [{
            splitLine: {
                show: false,
            },
            axisLabel: {
                show: false,
            },
            axisTick: {
                show: false,
            },
            axisLine: {
                show: false,
            },
        },
        {
            type: "value",
            max: max*2,
            splitLine: {
                show: false,
            },
            axisLabel: {
                show: false,
            },
            axisTick: {
                //y轴刻度线
                show: false,
            },
            axisLine: {
                //y轴
                show: false,
            },
        }],
        series: [
          {
            name: "累计同比增幅",
            type: "bar",
            barWidth: 30,
            yAxisIndex: 1,
            itemStyle: {
                normal: {
                    color: "#B4C7E7",
                    label: {
                        show: true,
                        position: 'top',
                        textStyle: {
                            color: "#0070CB",
                            fontSize: 10
                        },
                        formatter:function(params){ //标签内容
                            return  params.value+'%'
                        },
                    }
                },
            },
            data: cyCharts2
          },
          {
            name: "2021年完成(万元)",
            type: "line",
            itemStyle: {
                normal: {
                    color: "#00B050",
                    label: {
                        show: true,
                        position: 'bottom',
                        textStyle: {
                            color: "#00B050",
                            fontSize: 10
                        },
                    }
                },
            },
            data: cyCharts,
          },
          {
            name: "2022年完成(万元)",
            type: "line",
            itemStyle: {
                normal: {
                    color: "#FF0000",
                    label: {
                        show: true,
                        position: 'top',
                        textStyle: {
                            color: "#FF0000",
                        },
                    }
                },
            },
            data: cyCharts1,
          },
        ],
      };

      option && myChart.setOption(option);
    },
    headerClass() {
      return "background:#0070C0;color:#FFFF";
    },
  },
};
</script>

<style scoped lang="scss">
</style>
